
#delimit;
cd  "C:\Users\ejm5\Dropbox\IDS_PAPI";
use "C:\Users\ejm5\Dropbox\IDS_PAPI\data\bounds.dta", clear;
pause on;
xtset analysis_code stat;




lab var entry "Entry Costs";
rename entry Entry;
lab var land "Land Rts";
rename land Land;
lab var trans "Transparency";
rename trans Trans;
lab var time "Time Costs";
rename time Time;
lab var corrupt "Anti-Corruption";
rename corrupt Corrupt;
lab var soe "SOE Bias";
rename soe SOE;
lab var psd "Business Support";
rename psd BizSupprt;
lab var labor "Labor Policy";
rename labor Labor;
lab var legal "Dispute Res.";
rename legal Legal;
lab var pci "PCI";
rename pci PCI;
lab var proactive "Proactivity";
rename proactive Proactive;

replace analysis_code=12-analysis_code;

label define analysis_code 1 "Firm FE, Year FE & Controls" 2 "Firm Trend & Controls"  3 "Firm Trend" 4 "Firm & Year FEs" 5 "Firm FE" 6 "Prov. FE, Trend, Controls" 
7 "Prov. FE and Trend"  8 "Prov., Time, & Sector FE"  9 "Prov. & Time FE"  10 "Province FE"  11 "Bivariate", replace;

label values analysis_code analysis_code;



set more off;
foreach x in Entry Land Trans Time Corrupt SOE Proactive BizSupprt Labor Legal PCI{;
xtset analysis_code stat;
generate se_`x'=f.`x';
generate `x'_hi=`x'+(1.6*se_`x');
generate `x'_low=`x'-(1.6*se_`x');
twoway (rcap `x'_hi `x'_low analysis_code , lwidth(medium) horizontal sort(analysis_code) lcolor(gs6)) (scatter analysis_code `x' if stat==1, msymbol(triangle) mcolor(black) msize(small)), xline(0, lcolor(gs10)) xlab(-.5(.2).5, labsize(vsmall)) legend(off) 
title(`x', size(medsmall) margin(small)) ylab(1(1)11, nolabels) ytitle("") xtitle("Marginal Effect", size(small) margin(medsmall)) fysize(50) fxsize(25);
graph save `x'_bounds, replace;
}; 

#delimit;
twoway (rcap PCI_hi PCI_low analysis_code , lwidth(medium) horizontal sort(analysis_code) lcolor(gs6)) (scatter analysis_code PCI if stat==1, msymbol(triangle) mcolor(black) msize(small)), xline(0, lcolor(gs10)) xlab(-.5(.2).5, labsize(vsmall)) legend(off) 
title(PCI, size(medsmall) margin(small)) ylab(1(1)11, valuelabel  labsize(small) angle(45)) ytitle("", size(medsmall) margin(medsmall)) xtitle("Marginal Effect", size(small) margin(medsmall)) fysize(50) fxsize(40);
graph save `x'_bounds, replace;;
graph save pci_bounds, replace;

#delimit;
twoway (rcap Trans_hi Trans_low analysis_code , lwidth(medium) horizontal sort(analysis_code) lcolor(black)) (scatter analysis_code Trans if stat==1, msymbol(diamond) mcolor(gs6) msize(small)), xline(0, lcolor(gs10)) xlab(-.5(.2).5, labsize(vsmall)) legend(off) 
title(Transparency, size(medsmall) margin(small)) ylab(1(1)11, valuelabel labsize(small) angle(45)) ytitle("", size(medsmall) margin(medsmall)) xtitle("Marginal Effect", size(small) margin(medsmall)) fysize(50) fxsize(40);
graph save `x'_bounds, replace;;
graph save Trans_bounds, replace;

#delimit;
twoway (rcap Trans_hi Trans_low analysis_code , lwidth(medium) horizontal sort(analysis_code) lcolor(black)) (scatter analysis_code Trans if stat==1, msymbol(diamond) mcolor(gs6) msize(small)), xline(0, lcolor(gs10)) xlab(-.5(.2).5, labsize(vsmall)) legend(off) 
title(Transparency, size(medsmall) margin(small)) ylab(1(1)11, valuelabel labsize(small) angle(45)) ytitle("", size(medsmall) margin(medsmall)) xtitle("Marginal Effect", size(small) margin(medsmall));



graph combine PCI_bounds.gph Entry_bounds.gph Land_bounds.gph  Time_bounds.gph Corrupt_bounds.gph Trans_bounds.gph Soe_bounds.gph Proactive_bounds.gph Labor_bounds.gph Legal_bounds.gph, xcommon ycommon rows(2) imargin(tiny);
graph save Figure2.gph, replace;


/*********************************************************************************************************************************************************************************************************************/

#delimit;
use "C:\Users\ejm5\Dropbox\IDS_PAPI\data\bounds_indicators", clear;
pause on;

replace index_code=11-index_code;
drop if index_code<5;
replace index_code=index_code-4;

label define index_code 6 "Planning Docs Access" 5 "Legal Docs Access"  4 "Relationship Nesc." 3 "Tax Negotiation" 2 "Predictability of Law" 1 "Web Page Score", replace;

label values index_code index_code;

#delimit;
set more off;
foreach x in all priv_small fdi_small priv_large fdi_large{;
generate `x'_hi=`x'+(1.6*`x'_se);
generate `x'_low=`x'-(1.6*`x'_se);
}; 

#delimit;
twoway (rcap all_hi all_low index_code if index_code<=9, lwidth(medthick) horizontal sort(index_code) lcolor(black))
      (rcap all_hi all_low index_code if index_code==10, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code))
	   (scatter index_code all if index_code<=9, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code all if index_code==10, msymbol(diamond) mcolor(black) msize(medium)), 
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
 ylab(1(1)6, valuelabel labsize(vsmall) angle(45)) ytitle("") xtitle("Marginal Effect", size(medium) margin(medium)) 
 xlab(-2(.5)2, labsize(vsmall)) title("All Firms (n=347,690)", size(medlarge)) fysize(100) fxsize(50);
 graph save bound_all.gph, replace;
 
 
 #delimit;
twoway (rcap priv_small_hi priv_small_low index_code if index_code<=9, lwidth(medthick) horizontal sort(index_code) lcolor(black))
      (rcap priv_small_hi priv_small_low index_code if index_code==10, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code))
	   (scatter index_code priv_small if index_code<=9, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code priv_small if index_code==10, msymbol(diamond) mcolor(black) msize(medium)), 
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
ylab(1(1)6, valuelabel labsize(vsmall) angle(45)) ytitle("") xtitle("Marginal Effect", size(medsmall) margin(medsmall)) 
 xlab(-3.5(.5)2, labsize(vsmall)) title("Domestic SMEs (n=229,178)", size(medlarge));
 graph save bound_priv_small.gph, replace;
 
 
 #delimit;
twoway (rcap fdi_small_hi fdi_small_low index_code if index_code<=9, lwidth(medthick) horizontal sort(index_code) lcolor(black))
      (rcap fdi_small_hi fdi_small_low index_code if index_code==10, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code))
	   (scatter index_code fdi_small if index_code<=9, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code fdi_small if index_code==10, msymbol(diamond) mcolor(black) msize(medium)), 
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
ylab(1(1)6, valuelabel labsize(vsmall) angle(45)) ytitle("") xtitle("Marginal Effect",  size(medsmall) margin(medsmall)) 
 xlab(-5(1)2, labsize(vsmall)) title("Foreign SMEs (n=2,453)", size(medlarge));
 graph save bound_fdi_small.gph, replace;
 
 
 
 #delimit;
twoway (rcap priv_large_hi priv_large_low index_code if index_code<=9, lwidth(medthick) horizontal sort(index_code) lcolor(black))
      (rcap priv_large_hi priv_large_low index_code if index_code==10, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code))
	   (scatter index_code priv_large if index_code<=9, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code priv_large if index_code==10, msymbol(diamond) mcolor(black) msize(medium)), 
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
ylab(1(1)6, valuelabel labsize(vsmall) angle(45)) ytitle("") xtitle("Marginal Effect",  size(medsmall) margin(medsmall)) 
  xlab(-3.5(.5)2, labsize(vsmall)) title("Domestic Large (n=106,355)", size(medlarge));
 graph save bound_priv_large.gph, replace;
 
 
 #delimit;
twoway (rcap fdi_large_hi fdi_large_low index_code if index_code<=9, lwidth(medthick) horizontal sort(index_code) lcolor(black))
      (rcap fdi_large_hi fdi_large_low index_code if index_code==10, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code))
	   (scatter index_code fdi_large if index_code<=9, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code fdi_large if index_code==10, msymbol(diamond) mcolor(black) msize(medium)),  
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
ylab(1(1)6, valuelabel labsize(vsmall) angle(45)) ytitle("") xtitle("Marginal Effect",  size(medsmall) margin(medsmall)) 
 xlab(-3(.5)2.5, labsize(vsmall)) title("Foreign Large(n=9,370)", size(medlarge));
 graph save bound_fdi_large.gph, replace;
 
 #delimit;
 graph combine bound_priv_small.gph bound_fdi_small.gph bound_priv_large.gph bound_fdi_large.gph, ycommon rows(2) cols(2) imargin(tiny);
 graph save bounds_trans_type.gph, replace;
 
  #delimit;
 graph combine bound_all.gph bounds_trans_type.gph, cols(2) imargin(tiny);
 graph save bounds_trans_type.gph, replace;
 
 
 /************************************************************************************************************************************************************************************************************************/
#delimit;
 use "C:\Users\ejm5\Dropbox\IDS_PAPI\data\bounds_type", clear;

 #delimit;
replace index_code=11-index_code;
rename index_code index_code2;

#delimit;
label define index_code2 10 "Entry Costs" 9 "Land Rts"  8 "Transparency"  7 "Time Costs" 6 "Anti-Corruption" 5  "SOE Bias" 4 "Proactivity"   3 "Labor Policy"   2 "Dispute Res."  1 "PCI", replace;

label values index_code2 index_code2;

generate index_code_plus=index_code+.3;


set more off;
foreach x in priv fdi priv_small fdi_small priv_large fdi_large{;
generate `x'_hi=`x'+(1.6*`x'_se);
generate `x'_low=`x'-(1.6*`x'_se);
}; 


  
  
 #delimit;
twoway (rcap priv_hi priv_low index_code2 if index_code2 !=8, lwidth(medthick) horizontal sort(index_code2))
      (rcap priv_hi priv_low index_code2 if index_code2==8, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code2))
	   (scatter index_code2 priv if index_code2 !=8, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code2 priv if index_code2==8, msymbol(diamond) mcolor(black) msize(medium)), legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
 ylab(1(1)10, valuelabel labsize(small) angle(45)) ytitle("") xtitle("Marginal Effect", size(medium) margin(medium)) 
 xlab(-.5(.25).5, labsize(vsmall)) title("All Private", size(medlarge)) fysize(100) fxsize(55);
 graph save bound_priv.gph, replace; 
  
  
   #delimit;
twoway (rcap fdi_hi fdi_low index_code2 if index_code2 !=8, lwidth(medthick) horizontal sort(index_code2))
      (rcap fdi_hi fdi_low index_code2 if index_code2==8, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code2))
	   (scatter index_code2 fdi if index_code2 !=8, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code2 fdi if index_code2==8, msymbol(diamond) mcolor(black) msize(medium)), legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
 ylab(1(1)10, nolabels ) ytitle("") xtitle("Marginal Effect", size(medium) margin(medium)) 
 xlab(-.5(.25).5, labsize(vsmall)) title("All FDI", size(medlarge)) fysize(100) fxsize(40);
 graph save bound_fdi.gph, replace; 
  
  
 #delimit;
 graph combine bound_priv.gph bound_fdi.gph, ycommon cols(2) imargin(tiny); 
graph save bound_type_all.gph, replace;
  
  
  
  
  #delimit;
twoway (rcap priv_small_hi priv_small_low index_code2 if index_code2 !=8, lwidth(medthick) horizontal sort(index_code2) lcolor(black))
      (rcap priv_small_hi priv_small_low index_code2 if index_code2==8, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code2))
	   (scatter index_code2 priv_small if index_code2 !=8, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code2 priv_small if index_code2==8, msymbol(diamond) mcolor(black) msize(medium)), 
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
 ylab(1(1)10, valuelabel labsize(vsmall) angle(45)) ytitle("") xtitle("Marginal Effect", size(medsmall) margin(medsmall)) 
 xlab(-.5(.25).5, labsize(vsmall)) title("Domestic SMEs (n=229,178)", size(medium));
 graph save bound_priv_small2.gph, replace;
 

 #delimit;
twoway (rcap fdi_small_hi fdi_small_low index_code2 if index_code2!=8, lwidth(medthick) horizontal sort(index_code2))
      (rcap fdi_small_hi fdi_small_low index_code2 if index_code2==8, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code2))
	   (scatter index_code2 fdi_small if index_code2 !=8, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code2 fdi_small if index_code2==8, msymbol(diamond) mcolor(black) msize(medium)), 
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
 ylab(1(1)10, nolabel) ytitle("") xtitle("Marginal Effect",  size(medsmall) margin(medsmall))  
 xlab(-.5(.25).5, labsize(vsmall)) title("For. SMEs (n=2,453)", size(medium)) fxsize(27.5);
 graph save bound_fdi_small2.gph, replace;
 
 
 
 #delimit;
twoway (rcap priv_large_hi priv_large_low index_code2 if index_code2 !=8, lwidth(medthick) horizontal sort(index_code2))
      (rcap priv_large_hi priv_large_low index_code2 if index_code2==8, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code2))
	   (scatter index_code2 priv_large if index_code2 !=8, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code2 priv_large if index_code2==8, msymbol(diamond) mcolor(black) msize(medium)), 
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
 ylab(1(1)10, valuelabel labsize(vsmall) angle(45)) ytitle("") xtitle("Marginal Effect",  size(medsmall) margin(medsmall)) 
 xlab(-.5(.25).5, labsize(vsmall)) title("Domestic Large (n=106,355)", size(medium));
 graph save bound_priv_large2.gph, replace;
 
 
 #delimit;
twoway (rcap fdi_large_hi fdi_large_low index_code2 if index_code2 !=8, lwidth(medthick) horizontal sort(index_code2))
      (rcap fdi_large_hi fdi_large_low index_code2 if index_code2==8, lwidth(thick) lpattern(dash) lcolor(gs6) horizontal sort(index_code2))
	   (scatter index_code2 fdi_large if index_code2 !=8, msymbol(triangle) mcolor(gs6) msize(medsmall))
	   (scatter index_code2 fdi_large if index_code2==8, msymbol(diamond) mcolor(black) msize(medium)),  
legend(off) xline(0, lcolor(gs10) lpattern(dash) lwidth(medthick))
 ylab(1(1)10, nolabel) ytitle("") xtitle("Marginal Effect",  size(medsmall) margin(medsmall)) 
 xlab(-.5(.25).5, labsize(vsmall)) title("For. Large (n=9,370)", size(medium)) fxsize(27.5);
 graph save bound_fdi_large2.gph, replace;
 
 #delimit;
 graph combine bound_priv_small2.gph bound_fdi_small2.gph bound_priv_large2.gph bound_fdi_large2.gph, ycommon rows(2) cols(2) imargin(tiny);
 graph save bounds_trans_type2.gph, replace;
 
 #delimit;
 graph combine bound_type_all.gph bounds_trans_type2.gph,  cols(2) imargin(tiny);
 graph save final_bound_type.gph , replace;

 
 
 
 
